<template>
  <div class="index-container">
    <el-form :inline="true" class="search-form" @submit.native.prevent>
      <el-form-item>
        <el-input v-model="queryForm.name" size="small" :clearable="true" placeholder="搜索内容" @keyup.enter.native="submit" />
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" style="background-color: #2068B0;" @click="submit">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="List" border style="width: 100%">
      <el-table-column prop="name" label="新闻动态列表">
        <template slot-scope="scope">
          <span style="margin-left: 6px; margin-bottom: 0px; display: inline-block; width: 8px; height: 8px; background: #d5d2d1;margin-right: 8px;" />
          <span class="common-link" :title="scope.row.name" @click="navTo('/hj-home/'+tagName+'/detail/'+scope.row.id)">{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="time" label="发布时间" width="180">
        <template slot-scope="scope">{{ scope.row.createdAt.substring(0,10) }}</template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="dl-pagination"
      :hide-on-single-page="true"
      background
      layout="total, prev, pager, next, jumper"
      :total="total"
      :current-page="queryForm.page"
      :page-size="queryForm.size"
      @current-change="handleCurrentChange"
    />
  </div>
</template>
<script>
import { newsList } from '../../../api/web/news.js'
export default {
  data() {
    return {
      List: [],
      tagName: '',
      total: 0,
      queryForm: {
        page: 0,
        size: 10,
        name: '',
        sort: 'createdAt,desc'
      }
    }
  },
  created() {
    this.tagName = this.$route.meta.tagName
    this.queryList()
  },
  methods: {
    queryList() {
      this.loading = true
      newsList({page:this.queryForm.page-1,size:8,sort:'createdAt,desc',name:this.queryForm.name}).then(res => {
        this.loading = false
        this.List = res.content
        this.total = res.totalElements
      }).catch(_ => {
			    this.loading = false
			  })
    },
    // 当前页改变
    handleCurrentChange(val) {
      this.queryForm.page = val
      this.queryList()
    },
    submit() {
      this.queryForm.page = 1
      this.queryList()
    }
  }
}
</script>

<style>
	.search-form{
		text-align: right;
	}
</style>
